﻿namespace IBTrader.Indicator.CandleStick
{
    using IBTrader.Modules.Read;
    using System;

    class Item : Line
    {
        internal Line OpenLine, CloseLine;
        internal double High, Low, Open, Close, Volume;
        internal double BodyTop { get { return Math.Max(Open, Close); } }
        internal double BodyHeight { get { return Math.Abs(Open - Close); } }
        internal bool Up { get { return Open < Close; } }
        internal double Typical { get { return (High + Low + Close) / 3; } }
        internal double TrueRange(Item last)
        {
            var c1 = High - Low;
            return last == null ? c1 : Math.Max(c1, Math.Max(Math.Abs(High - last.Close), Math.Abs(Low - last.Close)));
        }
        internal protected virtual void Add(Line line)
        {
            if (OpenLine == null)
            {
                //Symbol = line.Symbol;
                DateTime = line.DateTime;
                High = Low = Open = Close = Price = line.Price;
                OpenLine = CloseLine = line;
            }
            else
            {
                High = Math.Max(High, line.Price);
                Low = Math.Min(Low, line.Price);
                Close = line.Price;
                CloseLine = line;
            }
        }
    }
}